In [11]:
using Plots,ApproxFun
plotlyjs()  # works in GR too;

Poisson equation $u_{\theta\theta} + u_{\phi\phi} = f(\theta,\phi)$


In [12]:
d=PeriodicInterval()^2
f=Fun((θ,ϕ)->exp(-10(sin(θ/2)^2+sin(ϕ/2)^2)),d)
A=lap(d)+.1I
u=A\f
plot(u)


Out[12]:

Laplace equation on the periodic strip $u_{\theta\theta} + u_{yy} = 0$


In [13]:
d=PeriodicInterval()*Interval()
g=Fun(z->real(cos(z)),(d))  # boundary data
u=[dirichlet(d);Laplacian(d)]\g
plot(u)


Out[13]:

Transport equation $u_t + u_\theta = 0$, $\theta \in (-2,2)$


In [15]:
=PeriodicInterval(-2.,2.);dt=Interval(0,3.)
d=*dt
=Derivative(d,[1,0]);Dt=Derivative(d,[0,1])
u=[I⊗ldirichlet(dt);Dt+]\Fun(θ->exp(-20θ^2),)
plot(u)


Out[15]:

$u_t + (1+\cos \theta) u_\theta = 0$


In [16]:
=PeriodicInterval();dt=Interval(0,2.)
d=*dt
=Derivative(d,[1,0]);Dt=Derivative(d,[0,1])
c=1+Fun(cos,)

#timedirichlet is [u[x,0], u[-1,t], u[1,t]

u=[I⊗ldirichlet(dt);Dt+c*]\Fun(θ->exp(-20θ^2),)
plot(u)


Out[16]:

$u_t = \sin \theta \,u_\theta$


In [6]:
=PeriodicInterval();dt=Interval(0,2.)
d=*dt
=Derivative(d,[1,0]);Dt=Derivative(d,[0,1])
a=Fun(sin,)

#timedirichlet is [u[x,0], u[-1,t], u[1,t]

u=[I⊗ldirichlet(dt);Dt-a*]\Fun(θ->exp(-20θ^2),)
plot(u)


Out[6]:

Convection Diffusion $u_t = \epsilon u_{\theta\theta} + u_\theta$


In [7]:
=PeriodicInterval();dt=Interval(0,10.)
d=*dt
ε=.01
=Derivative(d,[1,0]);Dt=Derivative(d,[0,1])

# Parentheses are a hack to get rank 2 PDE
u=[I⊗ldirichlet(dt);Dt-ε*^2-]\Fun(θ->exp(-20θ^2),)
plot(u)


Out[7]:

Wave equation $u_{tt} = u_{\theta\theta}$


In [8]:
=PeriodicInterval(-5.,5.);dt=Interval(0,20.)
d=*dt
=Derivative(d,[1,0]);Dt=Derivative(d,[0,1])
# need to specify both ic and its derivative
B=[I⊗ldirichlet(dt);I⊗lneumann(dt)]
u=pdesolve([B;Dt^2-^2],Fun(θ->exp(-20(θ-.1)^2),),200)
plot(u)


Out[8]:

Linear KdV


In [9]:
=PeriodicInterval(-10.0,2.);dt=Interval(0,.03);
d=*dt
=Derivative(d,[1,0]);Dt=Derivative(d,[0,1])
u=pdesolve([I⊗ldirichlet(dt);Dt+^3],Fun(θ->exp(-10θ^2),),200)
plot(u)


Out[9]:

Beam equation $$u_{tt}+u_{\theta\theta\theta\theta}=0$$


In [10]:
=PeriodicInterval(0.0,1.0);dt=Interval(0,0.03)
d=*dt
=Derivative(d,[1,0]);Dt=Derivative(d,[0,1]);

B=[I⊗ldirichlet(dt);I⊗lneumann(dt)]
u=pdesolve([B;Dt^2+^4],Fun(θ->exp(-200(θ-.5).^2),),200)
plot(u)


Out[10]: